package java101;

import java.util.*;

public class checkFormat {
	public enum ones {one, two, three, four, five, six, seven, eight, nine}
	public enum teens {ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen}
	public enum tens {twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety}
	public enum thous {thousand, million, billion}
	
	public static String text = "";
	public static int count=0;
		
	public static void main(String[] args)      {
		System.out.print("Enter Number to convert into words ");
		Scanner sc = new Scanner(System.in);
		long num = sc.nextInt();
		int res = 0;
		int i = 0;
		while(num > 0)
		{
			if(i == 0){						// i will = 0 1st pass
				res = (int) (num % 1000);	// Pick off 1st 3 digits
				printText(res);				// Add to print string
				num = num / 1000;
				i++;
				}
			else if(i > 0)					// i will be > 0 as was just incremented
			{
				res = (int) (num % 1000);	// Pick off next 3 digits
				if(res > 0)
					text = thous.values()[i - 1]+ " " + text;  // billions/millions/thousands
				printText(res);				// Add to print string
				num = num / 1000;
				i++;
				}
			}
		if(i > 0) {			

			text = Character.toUpperCase(text.charAt(0)) + text.substring(1);
			
			System.out.println(text);		// Print text string
		}
		else
			System.out.println("");
		}
	
	public static String printText(int num)
	{
//		text = "";
		if(!(num > 9 && num < 19))			// If not "Teen" special case
		{
			if(num % 10 > 0) {				// Pick off Ones
				
				getOnes(num % 10);			// Get Ones array value
			}
			num = num / 10;
			if(num % 10 > 0)				// Pick off Tens
				getTens(num % 10);			// Get Tens array value
			num = num / 10;
			if(num > 0)
				getHundreds(num);			// Get Hundreds array value (which is actually Ones value again)
			}
		else
		{
			getTeens(num % 10);				// Get "Teens" value special case
			}
	return text;
	}
	
	public static void getTeens(int num)
	{
		text = teens.values()[num]+ " " + text;
		}
	public static void getHundreds(int num)
	{
		text = ones.values()[num - 1]+ " hundred " + text;
		}
	public static void getTens(int num)
	{
			if(count>0) {
				text = tens.values()[num - 2]+ "-" + text;
			count--;
			}
			else {
				text = tens.values()[num-2]+ " " + text;
			}
		}

	public static void getOnes(int num)
	{
		text = ones.values()[num - 1]+ " " + text;
		count++;
		}
	} 